#include <stdio.h>
#include <stdlib.h>

/**
 * Return an array of arrays of size *returnSize.
 * The sizes of the arrays are returned as *returnColumnSizes array.
 * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().
 */
int** generate(int numRows, int* returnSize, int** returnColumnSizes) {
    *returnSize=numRows;
    *returnColumnSizes=(int*)malloc(sizeof(int)*numRows);
    int **r=(int**)malloc(sizeof(int*)*numRows);
    for( int i=0; i < numRows; ++i ) {
        (*returnColumnSizes)[i]=i+1;
        r[i]=(int*)malloc(sizeof(int)*(i+1));
        r[i][0]=r[i][i]=1;
        for( int j=1; j <= i-1; ++j ) 
            r[i][j] = r[i-1][j-1] + r[i-1][j];
    }
    return r;
}

int main(){
    int rS, *rCS=NULL;
    int **r=generate(7,&rS,&rCS);
    printf("%d \n",rS);
    return 0;
}
